<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller{
	private $web_config = 'config';
	public function __construct(){
		parent::__construct();
		@session_start();
		$this->web_config = $this->config->item('web');
		$this->load->library('form_validation');
		$this->load->helper('url');
	}

	public function index(){
		$news=$this->data->get_all('ca_news','1=1','*','info_id desc');
		$contact = $this->data->get_value('ca_article','aid=46','contents');
		$data=array(
			'news' 	  => $news,
			'contact' => $contact
		);
		$this->load->view(THEME_PATH . '/home.php', $data);
	}
	
	public function about(){
		$row = $this->data->get_one('ca_article',"aid='44'");
		$data=array(
			'row' 		=> $row
		);
		$this->load->view(THEME_PATH . '/home.php', $data);
	}

	public function products(){
		$category = $this->data->get_all('ca_product_category',"uid='0,'",'*',"my_order DESC,cate_id ASC");
		$data=array(
			'category' => $category
		);
		$this->load->view(THEME_PATH . '/home.php', $data);
	}
	
	public function services(){
		$services = $this->data->get_all('ca_article',"group_id=0",'*',"my_order DESC");
		$a = (int)$_GET['a'] ? (int)$_GET['a'] : (int)$services[0]['aid'];
		$row = $this->data->get_one('ca_article',"aid='$a'");
		$data=array(
			'a'  		=> $a,
			'services'  => $services,
			'row' 		=> $row
		);
		$this->load->view(THEME_PATH . '/home.php', $data);
	}
	
	public function news(){
		$news=$this->data->get_all('ca_news','1=1','*','info_id desc');
		$data=array(
			'news' => $news
		);
		$this->load->view(THEME_PATH . '/home.php', $data);
	}
	public function news_detail(){
		$i = (int)$_GET['i'];
		$row=$this->data->get_one('ca_news as n,ca_news_contents as c',"n.info_id='{$i}' AND n.info_id=c.info_id",'n.*,c.*');
		$data=array(
			'row' => $row
		);
		$this->load->view(THEME_PATH . '/home.php', $data);
	}
	
	public function contact(){
		$this->load->view(THEME_PATH . '/home.php', $data);
	}
	
	public function article(){
		$row = $this->data->get_one('ca_article',"aid='45'");
		$data=array(
			'row' => $row
		);
		$this->load->view(THEME_PATH . '/home.php', $data);
	}

	public function contact_action(){
		$this->form_validation->set_rules('name-mod', 'name', 'required');
		$this->form_validation->set_rules('email-mod', 'email', 'required');
		!$this->form_validation->run() && e_json(validation_errors(),0);
		$data=get_data($this->input->post());
		$data['acctime'] = time();
		$this->data->insert('ca_feedback',$data);
		e_json('',1);
	}
}